package cn.micai.base.lambda;

import java.util.function.Supplier;
import java.util.stream.Stream;

/**
 * 描述：重用一个流
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/21 18:03
 */
public class ReuseAStreamExample {

    public static void main(String [] args) {

        String [] array = {"a","b","c","d","e"};

        Supplier<Stream<String>> streamSupplier = () -> Stream.of(array);

        // get new stream
        streamSupplier.get().forEach(x->System.out.println(x));

        // get another new stream
        long count = streamSupplier.get().filter(x -> "b".equals(x)).count();
        System.out.println(count);

    }


}
